|
|
|
|
|
|
|
Methods of the Connection Object |
|
|
|
|
|
|
|
|
The Connection object has a lot of methods, but, once again, not all of them are important. Table 24.2 lists the most commonly used methods. |
|
|
|
|
| Table 24.2 Methods of the Connection Object. | | Method Name | Description | | Close | This method closes an open connection. | | Execute | Use this method to execute a stored procedure or any SQL action statement such as an INSERT, UPDATE, and DELETE. | | Open | After you have set the ConnectionString property, you call this method to open a connection to the data source. |
|
|
|
|
|
|
Creating a Connection Object |
|
|
|
|
|
|
|
|
Youll generally create one public Connection object that can be used throughout your application. You should only need one connection for a typical database application. There may be times when you need to open a second connection, but they should be kept to a minimum. Remember that connections are a scarce resource on a database server and should be opened only as necessary. Lets create a public Connection object in a BAS module. |
|
|
|
|
| Creating an ADO Project 1. In your employee project, youll need to reference the Microsoft ActiveX Data Objects 2.0 Library from the Project, References menu. 2. Add a BAS module to your employee project. 3. Set the Name property to modADO. 4. In the General Declarations section, add the following line of code: | | Public goConn As New ADODB.Connection | | This line of code creates a public variable called goConn that youll use throughout this application to create recordsets. Now, lets create a routine that opens a connection to a data source. You can use a few different types of connection strings to open a data source. It all depends on the |
|
|
|